//
//  GCW_SingerListViewController.m
//  MooMusic
//
//  Created by 管晨雯 on 15/10/26.
//  Copyright © 2015年 wjy. All rights reserved.
//

#import "GCW_SingerListViewController.h"
#import "GCW_SingerListTableViewCell.h"
#import "GCW_SingerListModel.h"
#import "NetWork.h"

// 导入头文件
#import "LTY_FilmAndSongsViewController.h"

@interface GCW_SingerListViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, strong) UITableView *singerListTbleView;

@property (nonatomic, strong) NSMutableArray *singerListArr;/* 歌手名数组 */

@end


static NSString *const cellReuse = @"cellReuse";
@implementation GCW_SingerListViewController

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.singerListArr = [NSMutableArray array];
    }
    
    return self;
}



- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    
    self.navigationItem.title = self.singerType;
//    self.view.backgroundColor = [UIColor cyanColor];
    self.navigationController.navigationBar.translucent = NO;
    
    self.singerListTbleView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 64) style:UITableViewStylePlain];
    
    self.singerListTbleView.dataSource = self;
    self.singerListTbleView.delegate = self;
    
    
    /*  注册cell */
    [self.singerListTbleView registerClass:[GCW_SingerListTableViewCell class] forCellReuseIdentifier:cellReuse];
    [self.view addSubview:self.singerListTbleView];
    
    
    [self createBackButton];
    [self getData];

}

#pragma mark --- 获取数据
- (void)getData
{
    NSString *url = [NSString  stringWithFormat:@"http://v1.ard.tj.itlily.com/ttpod?a=getnewttpod&id=%@&size=1000&page=1&app=ttpod&v=v8.0.1.2015091618",self.idNumber];

    [NetWork networkGETRequestWithURL:url Paramater:nil ResultBlock:^(id result) {
        
        NSMutableDictionary *mDic = (NSMutableDictionary *)result;
        
        NSMutableArray *dataArr = [mDic objectForKey:@"data"];
        
        for (NSMutableDictionary *dic in dataArr) {
            
            GCW_SingerListModel *model = [[GCW_SingerListModel alloc]init];
            [model setValuesForKeysWithDictionary:dic];
            [self.singerListArr addObject:model];
            //            NSLog(@"%@",model.singer_name);
            
        }
        
        if (self.singerListArr.count > 0) {
            [self.singerListTbleView reloadData];
        }
        
        
    }];
    
}




- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return  self.singerListArr.count;;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    GCW_SingerListTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellReuse];
    
    GCW_SingerListModel *model = [self.singerListArr objectAtIndex:indexPath.row];
    cell.listModel = model;
    
    return cell;
    
}


- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100 * HEIGH;
}

#pragma mark - 自定义导航栏返回按钮
- (void)createBackButton
{
    UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
    //    leftButton.frame = CGRectMake( 0, 0, 44, 44);
//    [leftButton contentRectForBounds:CGRectMake(0, 0, 30, 30)];
//    leftButton.contentEdgeInsets = UIEdgeInsetsMake(15, 15, 15, 15);
    leftButton.frame = CGRectMake(0, 0, 40, 40);
    leftButton.backgroundColor = [UIColor clearColor];
    
    
//    [leftButton setImage:[UIImage imageNamed:@"iconfont-xiangzuo-2@2x.png"] forState:UIControlStateNormal];
//        [self.navigationController.navigationBar addSubview:leftButton];
    
    [leftButton addTarget:self action:@selector(button1Cliked:) forControlEvents:UIControlEventTouchUpInside];
//    [leftButton setTitleColor:[UIColor yellowColor] forState:UIControlStateNormal];
    // 创建UIBarButtonItem
    //UIBarButtonItem *leftBar = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
    // 将leftBar赋给navigation的leftBarButton
    //self.navigationItem.leftBarButtonItem = leftBar;
    
    [self.navigationController.navigationBar addSubview:leftButton];
    

}

- (void)button1Cliked: (UIButton *)butoon
{
    [self dismissViewControllerAnimated:YES completion:^{
        
    }];
}


#pragma mark -- tableview的点击方法
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{

    NSLog(@"进入模板界面");
  //  NSString *string = [NSString stringWithFormat:SingerString, 拼接的singer_id]
    

    LTY_FilmAndSongsViewController *filmVC = [[LTY_FilmAndSongsViewController alloc]init];
    
    GCW_SingerListModel *model = [self.singerListArr objectAtIndex:indexPath.row];
    
    NSString *string = [NSString stringWithFormat:SingerString,model.singer_id];
    filmVC.DayString = string;
    filmVC.nameString = model.singer_name;
    // 定义一个标识符
    NSString *JudgeString = @"JudgeString";
    filmVC.JudgeString = JudgeString;
    
    [self.navigationController pushViewController:filmVC animated:YES];

}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
